﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace WpUserControls.UserControls
{
    public partial class RoundCornerButton : UserControl
    {
        public RoundCornerButton()
        {
            InitializeComponent();

            this.MouseEnter += new MouseEventHandler(myButton_MouseEnter);
            this.MouseLeave += new MouseEventHandler(myButton_MouseLeave);
        }

        private Brush _prevBorderBrush = null;

        void myButton_MouseEnter(object sender, MouseEventArgs e)
        {
            _prevBorderBrush = ButtonBorder.BorderBrush;
            ButtonBorder.BorderBrush = new SolidColorBrush(Colors.LightGray);
        }

        void myButton_MouseLeave(object sender, MouseEventArgs e)
        {
            ButtonBorder.BorderBrush = _prevBorderBrush ?? new SolidColorBrush(Colors.Transparent);
        }

        [Browsable(true)]
        public string Text
        {
            get
            {
                return textBlock.Text;
            }
            set
            {
                textBlock.Text = value;
            }
        }

        [Browsable(true)]
        public Thickness TextMargin
        {
            get
            {
                return textBlock.Margin;
            }
            set
            {
                textBlock.Margin = value;
            }
        }

        [Browsable(true)]
        public Brush ButtonBackground
        {
            get
            {
                return ButtonBorder.Background;
            }
            set
            {
                ButtonBorder.Background = value;
            }
        }

        [Browsable(true)]
        public new Thickness BorderThickness
        {
            get
            {
                return ButtonBorder.BorderThickness;
            }
            set
            {
                ButtonBorder.BorderThickness = value;
            }
        }

        [Browsable(true)]
        public new Brush BorderBrush
        {
            get
            {
                return ButtonBorder.BorderBrush;
            }
            set
            {
                ButtonBorder.BorderBrush = value;
            }
        }

        [Browsable(true)]
        public Orientation Orientation
        {
            get
            {
                return stackPanel.Orientation;
            }
            set
            {
                stackPanel.Orientation = value;
            }
        }

        [Browsable(true)]
        public CornerRadius CornerRadius
        {
            get
            {
                return ButtonBorder.CornerRadius;
            }
            set
            {
                ButtonBorder.CornerRadius = value;
            }
        }

        [Browsable(true)]
        public Thickness TextBorderThickness
        {
            get
            {
                return textBoxBorder.BorderThickness;
            }
            set
            {
                textBoxBorder.BorderThickness = value;
            }
        }

        [Browsable(true)]
        public Brush TextBorderBrush
        {
            get
            {
                return textBoxBorder.BorderBrush;
            }
            set
            {
                textBoxBorder.BorderBrush = value;
            }
        }

        #region ImageAhead

        [Browsable(true)]
        public ImageSource ImageAhead
        {
            get
            {
                return image1.Source;
            }
            set
            {
                image1.Source = value;
            }
        }

        [Browsable(true)]
        public string ImageAheadHeight
        {
            get
            {
                return double.IsNaN(image1.Height) ? "Auto" : image1.Height.ToString();
            }
            set
            {
                double height;
                if (double.TryParse(value, out height))
                {
                    image1.Height = height;
                }
                else
                {
                    image1.Height = double.NaN;
                }
            }
        }

        [Browsable(true)]
        public string ImageAheadWidth
        {
            get
            {
                return double.IsNaN(image1.Width) ? "Auto" : image1.Width.ToString();
            }
            set
            {
                double width;
                if (double.TryParse(value, out width))
                {
                    image1.Width = width;
                }
                else
                {
                    image1.Width = double.NaN;
                }
            }
        }

        [Browsable(true)]
        public Thickness ImageAheadBorderThickness
        {
            get
            {
                return imageAheadBorder.BorderThickness;
            }
            set
            {
                imageAheadBorder.BorderThickness = value;
            }
        }

        [Browsable(true)]
        public Brush ImageAheadBorderBrush
        {
            get
            {
                return imageAheadBorder.BorderBrush;
            }
            set
            {
                imageAheadBorder.BorderBrush = value;
            }
        }

        [Browsable(true)]
        public CornerRadius ImageAheadCornerRadius
        {
            get
            {
                return imageAheadBorder.CornerRadius;
            }
            set
            {
                imageAheadBorder.CornerRadius = value;
            }
        }

        #endregion ImageAhead

        #region ImageTail

        [Browsable(true)]
        public ImageSource ImageTail
        {
            get
            {
                return image2.Source;
            }
            set
            {
                image2.Source = value;
            }
        }

        [Browsable(true)]
        public string ImageTailHeight
        {
            get
            {
                return double.IsNaN(image2.Height) ? "Auto" : image2.Height.ToString();
            }
            set
            {
                double height;
                if (double.TryParse(value, out height))
                {
                    image2.Height = height;
                }
                else
                {
                    image2.Height = double.NaN;
                }
            }
        }

        [Browsable(true)]
        public string ImageTailWidth
        {
            get
            {
                return double.IsNaN(image2.Width) ? "Auto" : image2.Width.ToString();
            }
            set
            {
                double width;
                if (double.TryParse(value, out width))
                {
                    image2.Width = width;
                }
                else
                {
                    image2.Width = double.NaN;
                }
            }
        }

        [Browsable(true)]
        public Thickness ImageTailBorderThickness
        {
            get
            {
                return imageTailBorder.BorderThickness;
            }
            set
            {
                imageTailBorder.BorderThickness = value;
            }
        }

        [Browsable(true)]
        public Brush ImageTailBorderBrush
        {
            get
            {
                return imageTailBorder.BorderBrush;
            }
            set
            {
                imageTailBorder.BorderBrush = value;
            }
        }

        [Browsable(true)]
        public CornerRadius ImageTailCornerRadius
        {
            get
            {
                return imageTailBorder.CornerRadius;
            }
            set
            {
                imageTailBorder.CornerRadius = value;
            }
        }

        #endregion ImageTail
    }
}
